package cl.utalca.robot.services;

import java.sql.Connection;
import java.util.List;

import cl.utalca.DB.DataSourceManager;
import cl.utalca.robot.dto.LanguageDTO;
import cl.utalca.robot.logic.LanguageLogic;

public class LanguageService {

	public List<LanguageDTO> getLanguages(){
		
		Connection c = DataSourceManager.getConnection();
				
		LanguageLogic languageLogic = new LanguageLogic();
		List<LanguageDTO> resp = languageLogic.getLanguages(c);
		
		Boolean success = resp.size() > 0;
		DataSourceManager.close(c, success);
		
		return resp;
	}
	
	public LanguageDTO getLanguage(int languageId){
		
		Connection c = DataSourceManager.getConnection();
		
		LanguageLogic languageLogic = new LanguageLogic();
		LanguageDTO resp = languageLogic.getLanguage(languageId, c);
		
		Boolean success = resp != null;
		DataSourceManager.close(c, success);
		
		return resp;
	}
	
	public Boolean saveLanguage(LanguageDTO language){
		
		Connection c = DataSourceManager.getConnection();
		
		LanguageLogic langLogic = new LanguageLogic();
		int resp = langLogic.saveLanguage(language, c);
		
		Boolean success = resp != 0;
		DataSourceManager.close(c, success);
		
		return success;
	}
	
	public Boolean updateLanguage(LanguageDTO language){
		
		Connection c = DataSourceManager.getConnection();
		
		int resp = -1;
		LanguageLogic langLogic = new LanguageLogic();
		resp = langLogic.updateLanguage(language, c);
		
		Boolean success = resp > 0;
		DataSourceManager.close(c, success);
		
		return success;
	}
	
	public Boolean deleteLanguage(int languageId){
		
		Connection c = DataSourceManager.getConnection();
		
		int resp = -1;
		LanguageLogic langLogic = new LanguageLogic();
		resp = langLogic.deleteLanguage(languageId, c);
		
		Boolean success = resp > 0;
		DataSourceManager.close(c, success);
		
		return success;
	}
}
